const {
  get
} = require('../../utils/http')

Page({

  data: {
    latitude: 23.099994,
    longitude: 113.324520,
    markers: []
  },

  onReady() {
    this.getLocation();
    this.mapContext = wx.createMapContext('map')
    this.getMarkers();
  },
  async getMarkers() {
    let rs = await get('index.php/trade/get_list')
    console.log(rs);
    let list = [];
    rs.data.forEach((item, index) => {
      list.push({
        ...item,
        iconPath: item.type === 'buy' ? "/images/buy.png" : "/images/sell.png"
      })
    })
    this.setData({
      markers: list
    })
  },
  getLocation() {
    wx.getLocation({
      type: 'wgs84',
      success:(res)=> {
        this.setData({
          longitude:res.longitude,
          latitude:res.latitude
        })
      }
    })
  },
  movetocenter() {
    this.mapContext.moveToLocation();
  },
  goPublish() {
    wx.navigateTo({
      url: '/pages/publish/publish',
    })
  }
})